<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			<p>
				need a question:
				<input v-model="question">
			</p>
			<p>{{answer}}</p>
		</div>
		<script src="https://unpkg.com/vue/dist/vue.js"></script>
		<script src="https://unpkg.com/axios@0.12.0/dist/axios.min.js"></script>
		<script src="https://unpkg.com/lodash@4.13.1/lodash.min.js"></script>
		<script>
			var app=new Vue({
				el:'#app',
				data:{
					question:'',
					answer:'no answer'
				},
				watch:{
					question:function(nQuestion){
						this.answer="waiting for you to write...";
						this.getAnswer();
					}
				},
				methods:{
					getAnswer:_.debounce(
						function(){
							var vm=this;
							if(this.question.indexOf('?')===-1){
								vm.answer='question has not its design end'
								return
							}
							vm.answer='loading...'
							axios.get('https://yesno.wtf/api')
								.then(function(response){
									vm.answer=_.capitalize(response.data.answer)
								})
								.catch(function(error){
									vm.answer='there is no answer'+error
							})
						},500
					)
				}
			})
		</script>
	</body>
</html>

